<template>
  <div class="old-call-config">
  </div>
</template>
<script>
  export default {
    name: 'oldCallConfig',
    data () {
      return {
        message: '',
        iframeShow: false
      }
    },
    computed: {
      src () {
        return this.message
      }
    },
    methods: {
      getToken () {
        let sessionId = this.$store.state.session.sessionId
        this.$store.dispatch('getCCConfigUrl', {domain: window.location.href.split('/')[2]}).then((res) => {
          if (res.success) {
            this.message = `${res.url}?kf=vue&sessionId=${sessionId}`
//            this.message = `//114.215.205.38:8055/?kf=vue&sessionId=${sessionId}`
            let configIframe = document.getElementById('config-iframe')
            let configIframeWrap = document.getElementById('call_config_wrap')
            if (configIframe) {
              configIframe.setAttribute('src', this.message)
            }
            configIframe.style.display = 'block'
            configIframeWrap.style.display = 'block'
            this.iframeShow = true
          } else {
            if (res.code === 401) {
              this.$message.error(this.$t('config.agentInvalid'))
            } else if (res.code === 402) {
              this.$message.error(this.$t('config.agentNoOnline'))
            }
            this.iframeShow = false
          }
        })
      }
    },
    beforeRouteLeave (to, from, next) {
      let configIframe = document.getElementById('config-iframe')
      let configIframeWrap = document.getElementById('call_config_wrap')
      configIframe.style.display = 'none'
      configIframeWrap.style.display = 'none'
      next()
    },
    activated () {
      if (!this.iframeShow) {
        this.$nextTick(() => {
          this.getToken()
        })
      } else {
        let configIframe = document.getElementById('config-iframe')
        let configIframeWrap = document.getElementById('call_config_wrap')
        configIframe.style.display = 'block'
        configIframeWrap.style.display = 'block'
      }
    },
    mounted () {
    },
    beforeMount () {
//      this.getToken()
    }
  }
</script>
<style lang="stylus" scoped>
</style>
